package cn.tedu.wms.product.controller;

import cn.tedu.wms.product.pojo.dto.SupplierAddNewDTO;
import cn.tedu.wms.product.pojo.vo.SupplierListItemVO;
import cn.tedu.wms.product.pojo.vo.SupplierStandardVO;
import cn.tedu.wms.product.service.ISupplierService;
import cn.tedu.wms.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/suppliers")
@Api(tags = "01. 供应商管理模块")
public class SuplierController {

    @Autowired
    ISupplierService service;

    @ApiOperation("新增供应商")
    @ApiOperationSupport(order = 100)
    @PostMapping("/insert")
    public JsonResult<Void> addNew(SupplierAddNewDTO supplierAddNewDTO){
        log.info("开始处理添加管理员角色关联数据,参数:{}",supplierAddNewDTO);
        service.addNew(supplierAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除供应商")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(value = "供应商id",name="id",required = true,dataType ="long")
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> deleteById(@PathVariable Long id){
        log.info("准备删除的数据id:{}",id);
        service.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改供应商")
    @ApiOperationSupport(order = 300)
    @PostMapping("/update")
    public JsonResult<Void> update(SupplierStandardVO standardVO){
        log.info("准备修改的数据,参数:{}",standardVO);
        service.updateById(standardVO);
        return JsonResult.ok();
    }

    @ApiOperation("查询供应商详情")
    @ApiOperationSupport(order = 400)
    @ApiImplicitParam(name = "id",value = "供应商id",required = true,dataType = "long")
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<SupplierStandardVO> select(@PathVariable Long id){
        log.info("开始处理查询供应商详情,参数:{}",id);
        SupplierStandardVO queryResult = service.getStandardById(id);
        return JsonResult.ok(queryResult);
    }

    @ApiOperation("查询供应商列表")
    @ApiOperationSupport(order = 500)
    @GetMapping("")
    public JsonResult<List<SupplierListItemVO>> list(){
        log.info("开始处理查询供应商列表");
        List<SupplierListItemVO> list = service.list();
        return JsonResult.ok(list);
    }





}
